home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolfedit2 2.0.4 source.sit / WolfEdit2 2.0.4 Source / UEditWalls.p < prev    next >
Text File  |  1995-11-03  |  5KB  |  213 lines

  1. unit UEditWalls;
  2.  
  3. interface
  4.     uses
  5.         UWolfDoc;
  6.  
  7.     procedure EditWalls (mapList: TMapListDoc);
  8.  
  9. implementation
  10.     uses
  11.         UEditArt;
  12.  
  13.     const
  14.  
  15.         wallEditDlogID = 131;
  16.         splitViewItem = 5;
  17.         northSouthItem = 6;
  18.         eastWestItem = 7;
  19.         shadeItem = 8;
  20.         mirrorItem = 9;
  21.  
  22.     type
  23.  
  24.         TWallImagePalette = object(TImagePalette)
  25.                 procedure IWallImagePalette;
  26.                 procedure DrawImage (itemNo: integer; r: Rect);
  27.                 override;
  28.                 function ItemSelectable (item: integer): boolean;
  29.                 override;
  30.             end;
  31.  
  32.         TWallEditDialog = object(TArtEditDialog)
  33.                 fCurrentView: integer;
  34.                 procedure IWallEditDialog (itsMapList: TMapListDoc);
  35.                 procedure ItemHit (var e: EventInfo; itemNo: integer);
  36.                 override;
  37.                 procedure SelectView (viewNum: integer);
  38.                 function Split: boolean;
  39.                 function CurrentView: integer;
  40.                 procedure UninstallArt;
  41.                 override;
  42.                 procedure InstallArt;
  43.                 override;
  44.                 function ArtImageType: CustomImageType;
  45.                 override;
  46.                 function ArtImageCode: integer;
  47.                 override;
  48.                 procedure TWallEditDialog.ChangeImage (gworld: GWorldPtr; isThumbnail: boolean);
  49.                 override;
  50.             end;
  51.  
  52.     procedure TWallImagePalette.IWallImagePalette;
  53.     begin
  54.         IImagePalette(16, 29);
  55.         fDialog := nil;
  56.     end;
  57.  
  58.     procedure TWallImagePalette.DrawImage (itemNo: integer; r: Rect);
  59.     begin
  60.         fDialog.fMapList.PlotWall($81 + itemNo, r)
  61.     end;
  62.  
  63.     function TWallImagePalette.ItemSelectable (item: integer): boolean;
  64.     begin
  65.         ItemSelectable := fDialog.fMapList.WallAvailable($81 + item);
  66.     end;
  67.  
  68.     procedure TWallEditDialog.IWallEditDialog (itsMapList: TMapListDoc);
  69.         var
  70.             palette: TWallImagePalette;
  71.     begin
  72.         new(palette);
  73.         palette.IWallImagePalette;
  74.         IArtEditDialog(wallEditDlogID, palette, itsMapList, true);
  75.         fArtView.fRemoveWhite := true;
  76.         palette.fDialog := self;
  77.         DefineGroup(northSouthItem, eastWestItem);
  78.         fCurrentView := northSouthView;
  79.     end;
  80.  
  81.     procedure TWallEditDialog.ItemHit (var e: EventInfo; itemNo: integer);
  82.         var
  83.             value: integer;
  84.     begin
  85.         inherited ItemHit(e, itemNo);
  86.         value := GetItemValue(itemNo);
  87.         case itemNo of
  88.             northSouthItem: 
  89.                 SelectView(northSouthView);
  90.             eastWestItem: 
  91.                 SelectView(eastWestView);
  92.             otherwise
  93.                 ;
  94.         end;
  95.     end;
  96.  
  97.     procedure TWallEditDialog.SelectView (viewNum: integer);
  98.     begin
  99.         if viewNum <> fCurrentView then begin
  100.                 UninstallArt;
  101.                 fCurrentView := viewNum;
  102.                 InstallArt;
  103.             end;
  104.     end;
  105.  
  106.     function TWallEditDialog.Split: boolean;
  107.     begin
  108.         Split := GetItemValue(splitViewItem) <> 0;
  109.     end;
  110.  
  111.     function TWallEditDialog.CurrentView: integer;
  112.     begin
  113.         if Split then
  114.             CurrentView := fCurrentView
  115.         else
  116.             CurrentView := bothViews;
  117.     end;
  118.  
  119.     procedure TWallEditDialog.UninstallArt;
  120.         var
  121.             wal: WallArtListHandle;
  122.             i: integer;
  123.  
  124.         procedure Uninstall (var this, other: WallArtListEntry);
  125.             var
  126.                 code: integer;
  127.                 view: integer;
  128.         begin
  129.             view := CurrentView;
  130.             if fArtView.fChanged then begin
  131.                     if (this.art <> nil) & (this.art <> other.art) then
  132.                         DisposHandle(this.art);
  133.                     this.art := fArtView.ExtractWall;
  134.                     if not Split then begin
  135.                             if other.art <> nil then
  136.                                 DisposHandle(other.art);
  137.                             other.art := this.art;
  138.                         end;
  139.                     fMapList.Changed;
  140.                     fArtView.fChanged := false;
  141.                 end;
  142.             UninstallFlag(this.darkFlag, shadeItem);
  143.             UninstallFlag(this.mirrorFlag, mirrorItem);
  144.         end;
  145.  
  146.     begin {TWallEditDialog.UninstallArt}
  147.         if fCurrentArt >= 0 then begin
  148.                 wal := fMapList.GetWallArtList;
  149.                 HLock(Handle(wal));
  150.                 i := 2 * fCurrentArt;
  151.                 Uninstall(wal^^[i + fCurrentView], wal^^[i + 1 - fCurrentView]);
  152.                 HUnlock(Handle(wal));
  153.             end;
  154.     end;
  155.  
  156.     procedure TWallEditDialog.InstallArt;
  157.         var
  158.             wal: WallArtListHandle;
  159.             i: integer;
  160.  
  161.         procedure Install (this, other: WallArtListEntry);
  162.         begin
  163.             fArtView.InstallWall(this.art);
  164.             InstallFlag(this.art <> other.art, splitViewItem);
  165.             InstallFlag(this.darkFlag, shadeItem);
  166.             InstallFlag(this.mirrorFlag, mirrorItem);
  167.         end;
  168.  
  169.     begin {TWallEditDialog.InstallArt}
  170.         if fCurrentArt >= 0 then begin
  171.                 wal := fMapList.GetWallArtList;
  172.                 HLock(Handle(wal));
  173.                 i := 2 * fCurrentArt;
  174.                 Install(wal^^[i + fCurrentView], wal^^[i + 1 - fCurrentView]);
  175.                 HUnlock(Handle(wal));
  176.             end;
  177.     end;
  178.  
  179.     function TWallEditDialog.ArtImageType: CustomImageType;
  180.     begin
  181.         ArtImageType := wallImage;
  182.     end;
  183.  
  184.     function TWallEditDialog.ArtImageCode: integer;
  185.     begin
  186.         ArtImageCode := $81 + fCurrentArt;
  187.     end;
  188.  
  189.     procedure TWallEditDialog.ChangeImage (gworld: GWorldPtr; isThumbnail: boolean);
  190.     begin
  191.         fMapList.InstallWallImage(ArtImageCode, CurrentView, gworld);
  192.     end;
  193.  
  194.     procedure EditWalls (mapList: TMapListDoc);
  195.         var
  196.             dlog: TWallEditDialog;
  197.  
  198.         procedure CheckWindow (win: TWindow);
  199.         begin
  200.             if member(win, TWallEditDialog) then begin
  201.                     win.Select;
  202.                     exit(EditWalls);
  203.                 end;
  204.         end;
  205.  
  206.     begin {EditWalls}
  207.         mapList.EachWindowDo(CheckWindow);
  208.         new(dlog);
  209.         dlog.IWallEditDialog(mapList);
  210.         dlog.Show;
  211.     end;
  212.  
  213. end.